# -*- mode: conf -*-

[Unit]
Description=Prometheus Alertmanager.
Documentation=https://github.com/prometheus/alertmanager
After=network.target

[Service]
{% if ansible_processor_vcpus > 1 %}
Environment=GOMAXPROCS={{ (ansible_processor_vcpus * 0.5 + 1)|int }}
{% else %}
Environment=GOMAXPROCS=1
{% endif %}
EnvironmentFile=-/etc/default/alertmanager
User=prometheus
LimitNOFILE={{ prometheus_arg.ulimit_nofile }}
LimitNPROC={{ prometheus_arg.ulimit_nproc }}
LimitCORE={{ prometheus_arg.ulimit_core }}
LimitMEMLOCK={{ prometheus_arg.ulimit_memlock }}
ExecStart=/usr/bin/alertmanager \
          --web.listen-address={{ ansible_default_ipv4.address }}:{{ prometheus_port.alertmanager }} \
          --config.file={{ prometheus_conf_path }}/alertmanager.yml \
          --storage.path={{ prometheus_data_path }}/alertmanager \
          --cluster.reconnect-interval=5s \
          --cluster.listen-address={{ ansible_default_ipv4.address }}:{{ prometheus_port.cluster }} \
          --cluster.advertise-address={{ ansible_default_ipv4.address }}:{{ prometheus_port.alertmanager }} \
{% if prometheus_server | length > 1 %}
{% for peer in prometheus_server %}
          --cluster.peer={{ peer }}:{{ prometheus_port.cluster }} \
{% endfor %}
{% endif %}
          $ALERTMANAGER_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=30s

[Install]
WantedBy=multi-user.target
